
package com.shop.cloud.live.admin.util;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import jakarta.websocket.Session;
/**
 * 直播Map工具
 * @author
 */
@Slf4j
public class MapUtil {

    /**
     * 获取map中含有key前缀的Session列表集合
     * @param map
     * @param keyPrefix key前缀
     * @return
     */
    public static List<Session> getSessionByKeyPrefix(ConcurrentHashMap<String, Session> map, String keyPrefix) {
        List<Session> sessionList = new ArrayList<>();
        for (String key : map.keySet()) {
            if (key.startsWith(keyPrefix)) {
                sessionList.add(map.get(key));
            }
        }
        return sessionList;
    }
}
